<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Tiny FTP: ftp_client.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">Tiny FTP
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle"><div class="title">ftp_client.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &quot;ftp_client.h&quot;</code><br />
<code>#include &quot;cmd_client.h&quot;</code><br />
<code>#include &quot;config.h&quot;</code><br />
<code>#include &lt;arpa/inet.h&gt;</code><br />
<code>#include &lt;time.h&gt;</code><br />
<code>#include &lt;ctype.h&gt;</code><br />
<code>#include &lt;dirent.h&gt;</code><br />
<code>#include &lt;errno.h&gt;</code><br />
<code>#include &lt;fcntl.h&gt;</code><br />
<code>#include &lt;netdb.h&gt;</code><br />
<code>#include &lt;netinet/in.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;strings.h&gt;</code><br />
<code>#include &lt;sys/socket.h&gt;</code><br />
<code>#include &lt;sys/stat.h&gt;</code><br />
<code>#include &lt;sys/time.h&gt;</code><br />
<code>#include &lt;sys/types.h&gt;</code><br />
<code>#include &lt;termios.h&gt;</code><br />
<code>#include &lt;unistd.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for ftp_client.c:</div>
<div class="dyncontent">
<div class="center"><img src="ftp__client_8c__incl.png" border="0" usemap="#aftp__client_8c" alt=""/></div>
<map name="aftp__client_8c" id="aftp__client_8c">
<area shape="rect" title=" " alt="" coords="837,5,932,32"/>
<area shape="rect" href="ftp__client_8h_source.html" title=" " alt="" coords="5,155,100,181"/>
<area shape="rect" href="cmd__client_8h_source.html" title=" " alt="" coords="589,80,695,107"/>
<area shape="rect" title=" " alt="" coords="124,155,192,181"/>
<area shape="rect" title=" " alt="" coords="216,155,287,181"/>
<area shape="rect" title=" " alt="" coords="311,155,386,181"/>
<area shape="rect" title=" " alt="" coords="411,155,513,181"/>
<area shape="rect" title=" " alt="" coords="538,155,634,181"/>
<area shape="rect" title=" " alt="" coords="658,155,743,181"/>
<area shape="rect" title=" " alt="" coords="767,155,863,181"/>
<area shape="rect" title=" " alt="" coords="888,155,980,181"/>
<area shape="rect" title=" " alt="" coords="1005,155,1077,181"/>
<area shape="rect" title=" " alt="" coords="1101,155,1164,181"/>
<area shape="rect" href="config_8h_source.html" title=" " alt="" coords="1189,155,1263,181"/>
<area shape="rect" title=" " alt="" coords="1023,80,1087,107"/>
<area shape="rect" title=" " alt="" coords="1112,80,1183,107"/>
<area shape="rect" title=" " alt="" coords="1207,80,1277,107"/>
<area shape="rect" title=" " alt="" coords="1302,80,1369,107"/>
<area shape="rect" title=" " alt="" coords="1393,80,1464,107"/>
<area shape="rect" title=" " alt="" coords="1488,80,1567,107"/>
<area shape="rect" title=" " alt="" coords="1591,80,1682,107"/>
<area shape="rect" title=" " alt="" coords="1707,80,1791,107"/>
</map>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a8dc414d1afe7fc1bbdd1c06d682ba7f3"><td class="memItemLeft" align="right" valign="top"><a id="a8dc414d1afe7fc1bbdd1c06d682ba7f3" name="a8dc414d1afe7fc1bbdd1c06d682ba7f3"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>DEFAULT_FTP_PORT</b>&#160;&#160;&#160;21</td></tr>
<tr class="separator:a8dc414d1afe7fc1bbdd1c06d682ba7f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa9e26136af09184e7b167db6e01d6e8e"><td class="memItemLeft" align="right" valign="top"><a id="aa9e26136af09184e7b167db6e01d6e8e" name="aa9e26136af09184e7b167db6e01d6e8e"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>RCV_BUF_MAX_LEN</b>&#160;&#160;&#160;510</td></tr>
<tr class="separator:aa9e26136af09184e7b167db6e01d6e8e"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ae82ce0c2ad9bca58caa399c290effbca"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#ae82ce0c2ad9bca58caa399c290effbca">cmd_err_exit</a> (char *err_msg, int err_code)</td></tr>
<tr class="memdesc:ae82ce0c2ad9bca58caa399c290effbca"><td class="mdescLeft">&#160;</td><td class="mdescRight">打印报错信息并退出。  <a href="ftp__client_8c.html#ae82ce0c2ad9bca58caa399c290effbca">More...</a><br /></td></tr>
<tr class="separator:ae82ce0c2ad9bca58caa399c290effbca"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a50af3c8dbaa13d610ab72731646b8001"><td class="memItemLeft" align="right" valign="top"><a id="a50af3c8dbaa13d610ab72731646b8001" name="a50af3c8dbaa13d610ab72731646b8001"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>echo_off</b> (void)</td></tr>
<tr class="memdesc:a50af3c8dbaa13d610ab72731646b8001"><td class="mdescLeft">&#160;</td><td class="mdescRight">关闭显示输入字符（用于输入密码） <br /></td></tr>
<tr class="separator:a50af3c8dbaa13d610ab72731646b8001"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a13c96b2939a5739cc81b955b32a98f4e"><td class="memItemLeft" align="right" valign="top"><a id="a13c96b2939a5739cc81b955b32a98f4e" name="a13c96b2939a5739cc81b955b32a98f4e"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>echo_on</b> (void)</td></tr>
<tr class="memdesc:a13c96b2939a5739cc81b955b32a98f4e"><td class="mdescLeft">&#160;</td><td class="mdescRight">打开显示输入字符 <br /></td></tr>
<tr class="separator:a13c96b2939a5739cc81b955b32a98f4e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:acc60139a882577df9182dec7cf130a95"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#acc60139a882577df9182dec7cf130a95">ftp_get_reply</a> (int sock_fd)</td></tr>
<tr class="memdesc:acc60139a882577df9182dec7cf130a95"><td class="mdescLeft">&#160;</td><td class="mdescRight">接受来自服务端的回应。  <a href="ftp__client_8c.html#acc60139a882577df9182dec7cf130a95">More...</a><br /></td></tr>
<tr class="separator:acc60139a882577df9182dec7cf130a95"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3d3917e46b692a63525f64f0bb1c975d"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a3d3917e46b692a63525f64f0bb1c975d">ftp_send_cmd</a> (const char *s1, const char *s2, int sock_fd)</td></tr>
<tr class="memdesc:a3d3917e46b692a63525f64f0bb1c975d"><td class="mdescLeft">&#160;</td><td class="mdescRight">拼接给出的两个参数后向客户端发送。  <a href="ftp__client_8c.html#a3d3917e46b692a63525f64f0bb1c975d">More...</a><br /></td></tr>
<tr class="separator:a3d3917e46b692a63525f64f0bb1c975d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2da1039d0b9c00763143e93f44ca7416"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a2da1039d0b9c00763143e93f44ca7416">xconnect</a> (struct sockaddr_in *s_addr)</td></tr>
<tr class="memdesc:a2da1039d0b9c00763143e93f44ca7416"><td class="mdescLeft">&#160;</td><td class="mdescRight">连接到服务器。  <a href="ftp__client_8c.html#a2da1039d0b9c00763143e93f44ca7416">More...</a><br /></td></tr>
<tr class="separator:a2da1039d0b9c00763143e93f44ca7416"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0d2d0ee5a8e9a4e4a5f215b52d7e73c2"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a0d2d0ee5a8e9a4e4a5f215b52d7e73c2">rand_local_port</a> ()</td></tr>
<tr class="memdesc:a0d2d0ee5a8e9a4e4a5f215b52d7e73c2"><td class="mdescLeft">&#160;</td><td class="mdescRight">PORT模式下，随机生成一个端口号。  <a href="ftp__client_8c.html#a0d2d0ee5a8e9a4e4a5f215b52d7e73c2">More...</a><br /></td></tr>
<tr class="separator:a0d2d0ee5a8e9a4e4a5f215b52d7e73c2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac95cce0b3a2123cc408859183557ab80"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#ac95cce0b3a2123cc408859183557ab80">get_port</a> ()</td></tr>
<tr class="memdesc:ac95cce0b3a2123cc408859183557ab80"><td class="mdescLeft">&#160;</td><td class="mdescRight">pasv模式下，向server发送PASV指令，接收server发回的端口号（第一次握手  <a href="ftp__client_8c.html#ac95cce0b3a2123cc408859183557ab80">More...</a><br /></td></tr>
<tr class="separator:ac95cce0b3a2123cc408859183557ab80"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a007aca7a47d99c72aea9dac4faa64ce9"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a007aca7a47d99c72aea9dac4faa64ce9">xconnect_ftpdata</a> (<a class="el" href="structMsg.html">Msg</a> *msg)</td></tr>
<tr class="memdesc:a007aca7a47d99c72aea9dac4faa64ce9"><td class="mdescLeft">&#160;</td><td class="mdescRight">建立数据连接，被动模式下，从server获得端口号，通过server打开的这个端口与server建立数据连接;主动模式下，client指定本地端口号后，向server发PORT指令，然后建立一个新的数据连接。  <a href="ftp__client_8c.html#a007aca7a47d99c72aea9dac4faa64ce9">More...</a><br /></td></tr>
<tr class="separator:a007aca7a47d99c72aea9dac4faa64ce9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6a1e56fcb9d9f48e879662a60d9eab4d"><td class="memItemLeft" align="right" valign="top"><a id="a6a1e56fcb9d9f48e879662a60d9eab4d" name="a6a1e56fcb9d9f48e879662a60d9eab4d"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>get_user</b> ()</td></tr>
<tr class="memdesc:a6a1e56fcb9d9f48e879662a60d9eab4d"><td class="mdescLeft">&#160;</td><td class="mdescRight">获取用户名。 <br /></td></tr>
<tr class="separator:a6a1e56fcb9d9f48e879662a60d9eab4d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5eba4ccb7f43b916606b7a703782e6ce"><td class="memItemLeft" align="right" valign="top"><a id="a5eba4ccb7f43b916606b7a703782e6ce" name="a5eba4ccb7f43b916606b7a703782e6ce"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>get_pass</b> ()</td></tr>
<tr class="memdesc:a5eba4ccb7f43b916606b7a703782e6ce"><td class="mdescLeft">&#160;</td><td class="mdescRight">获取密码。 <br /></td></tr>
<tr class="separator:a5eba4ccb7f43b916606b7a703782e6ce"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a048633927810eee4b247c8a43cbb40bf"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a048633927810eee4b247c8a43cbb40bf">ftp_login</a> ()</td></tr>
<tr class="memdesc:a048633927810eee4b247c8a43cbb40bf"><td class="mdescLeft">&#160;</td><td class="mdescRight">客户端登录交互。  <a href="ftp__client_8c.html#a048633927810eee4b247c8a43cbb40bf">More...</a><br /></td></tr>
<tr class="separator:a048633927810eee4b247c8a43cbb40bf"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6c6decfc6f699c73ab480c3f91882794"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a6c6decfc6f699c73ab480c3f91882794">fill_host_addr</a> (char *host_ip_addr, struct sockaddr_in *host, int port)</td></tr>
<tr class="memdesc:a6c6decfc6f699c73ab480c3f91882794"><td class="mdescLeft">&#160;</td><td class="mdescRight">设置客户端的sockaddr_in。  <a href="ftp__client_8c.html#a6c6decfc6f699c73ab480c3f91882794">More...</a><br /></td></tr>
<tr class="separator:a6c6decfc6f699c73ab480c3f91882794"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a710ede996572b54a3e6a014f5f842ecb"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="ftp__client_8c.html#a710ede996572b54a3e6a014f5f842ecb">ftp_user_cmd</a> (char *user_cmd)</td></tr>
<tr class="memdesc:a710ede996572b54a3e6a014f5f842ecb"><td class="mdescLeft">&#160;</td><td class="mdescRight">格式化指令,对错误指令返回ERROR flag  <a href="ftp__client_8c.html#a710ede996572b54a3e6a014f5f842ecb">More...</a><br /></td></tr>
<tr class="separator:a710ede996572b54a3e6a014f5f842ecb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2ae066576c5647d286a8033faa0ee221"><td class="memItemLeft" align="right" valign="top"><a id="a2ae066576c5647d286a8033faa0ee221" name="a2ae066576c5647d286a8033faa0ee221"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>start_ftp_cmd</b> (char *host_ip_addr, int port)</td></tr>
<tr class="memdesc:a2ae066576c5647d286a8033faa0ee221"><td class="mdescLeft">&#160;</td><td class="mdescRight">处理启动之后与用户的交互。 <br /></td></tr>
<tr class="separator:a2ae066576c5647d286a8033faa0ee221"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0ddf1224851353fc92bfbff6f499fa97"><td class="memItemLeft" align="right" valign="top"><a id="a0ddf1224851353fc92bfbff6f499fa97" name="a0ddf1224851353fc92bfbff6f499fa97"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>main</b> (int argc, char *argv[])</td></tr>
<tr class="memdesc:a0ddf1224851353fc92bfbff6f499fa97"><td class="mdescLeft">&#160;</td><td class="mdescRight">启动客户端，要求ip地址参数。默认在端口21启动。 <br /></td></tr>
<tr class="separator:a0ddf1224851353fc92bfbff6f499fa97"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="var-members" name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a86aba5265147ee71567e55f3c92f9df5"><td class="memItemLeft" align="right" valign="top"><a id="a86aba5265147ee71567e55f3c92f9df5" name="a86aba5265147ee71567e55f3c92f9df5"></a>
struct sockaddr_in ftp_server&#160;</td><td class="memItemRight" valign="bottom"><b>local_host</b></td></tr>
<tr class="separator:a86aba5265147ee71567e55f3c92f9df5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aff32f3e23f89ed16d3e948b1948a0274"><td class="memItemLeft" align="right" valign="top"><a id="aff32f3e23f89ed16d3e948b1948a0274" name="aff32f3e23f89ed16d3e948b1948a0274"></a>
struct hostent *&#160;</td><td class="memItemRight" valign="bottom"><b>server_hostent</b></td></tr>
<tr class="separator:aff32f3e23f89ed16d3e948b1948a0274"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a83ce7994ea94971c6e4b0ed94b53651e"><td class="memItemLeft" align="right" valign="top"><a id="a83ce7994ea94971c6e4b0ed94b53651e" name="a83ce7994ea94971c6e4b0ed94b53651e"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>sock_control</b></td></tr>
<tr class="separator:a83ce7994ea94971c6e4b0ed94b53651e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2338ae28f14b9f119ed21868867b17d1"><td class="memItemLeft" align="right" valign="top"><a id="a2338ae28f14b9f119ed21868867b17d1" name="a2338ae28f14b9f119ed21868867b17d1"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>user</b> [64]</td></tr>
<tr class="separator:a2338ae28f14b9f119ed21868867b17d1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0866d4203d1162af18c125c88ed199ce"><td class="memItemLeft" align="right" valign="top"><a id="a0866d4203d1162af18c125c88ed199ce" name="a0866d4203d1162af18c125c88ed199ce"></a>
char&#160;</td><td class="memItemRight" valign="bottom"><b>passwd</b> [64]</td></tr>
<tr class="separator:a0866d4203d1162af18c125c88ed199ce"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1ea5d0cb93f22f7d0fdf804bd68c3326"><td class="memItemLeft" align="right" valign="top"><a id="a1ea5d0cb93f22f7d0fdf804bd68c3326" name="a1ea5d0cb93f22f7d0fdf804bd68c3326"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>mode</b> = PORT</td></tr>
<tr class="separator:a1ea5d0cb93f22f7d0fdf804bd68c3326"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Code for ftp client, basic connection to a local ftp server, connection host ip:127.0.0.1, default port:21.</p>
<dl class="section author"><dt>Author</dt><dd>ssr </dd></dl>
<dl class="section version"><dt>Version</dt><dd>V1.0 </dd></dl>
<dl class="section date"><dt>Date</dt><dd>2022-11-6 </dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>GNU Public License V3.0 </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ae82ce0c2ad9bca58caa399c290effbca" name="ae82ce0c2ad9bca58caa399c290effbca"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae82ce0c2ad9bca58caa399c290effbca">&#9670;&nbsp;</a></span>cmd_err_exit()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cmd_err_exit </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>err_msg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>err_code</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>打印报错信息并退出。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">err_msg</td><td></td></tr>
    <tr><td class="paramname">err_code</td><td></td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a6c6decfc6f699c73ab480c3f91882794" name="a6c6decfc6f699c73ab480c3f91882794"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6c6decfc6f699c73ab480c3f91882794">&#9670;&nbsp;</a></span>fill_host_addr()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int fill_host_addr </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>host_ip_addr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">struct sockaddr_in *&#160;</td>
          <td class="paramname"><em>host</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>port</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>设置客户端的sockaddr_in。 </p>
<dl class="section return"><dt>Returns</dt><dd>成功则返回1,失败则返回错误码。 </dd></dl>

</div>
</div>
<a id="acc60139a882577df9182dec7cf130a95" name="acc60139a882577df9182dec7cf130a95"></a>
<h2 class="memtitle"><span class="permalink"><a href="#acc60139a882577df9182dec7cf130a95">&#9670;&nbsp;</a></span>ftp_get_reply()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int ftp_get_reply </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sock_fd</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>接受来自服务端的回应。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">sock_fd</td><td>连接服务端的套接字。 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>若输入为空，返回0；否则返回对应的reply_code数字。 </dd></dl>

</div>
</div>
<a id="a048633927810eee4b247c8a43cbb40bf" name="a048633927810eee4b247c8a43cbb40bf"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a048633927810eee4b247c8a43cbb40bf">&#9670;&nbsp;</a></span>ftp_login()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int ftp_login </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>客户端登录交互。 </p>
<dl class="section return"><dt>Returns</dt><dd>登录成功则返回1,否则返回0。 </dd></dl>

</div>
</div>
<a id="a3d3917e46b692a63525f64f0bb1c975d" name="a3d3917e46b692a63525f64f0bb1c975d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3d3917e46b692a63525f64f0bb1c975d">&#9670;&nbsp;</a></span>ftp_send_cmd()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int ftp_send_cmd </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>s1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>s2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>sock_fd</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>拼接给出的两个参数后向客户端发送。 </p>
<dl class="section return"><dt>Returns</dt><dd>成功则返回发送的字符数，否则返回-1。 </dd></dl>

</div>
</div>
<a id="a710ede996572b54a3e6a014f5f842ecb" name="a710ede996572b54a3e6a014f5f842ecb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a710ede996572b54a3e6a014f5f842ecb">&#9670;&nbsp;</a></span>ftp_user_cmd()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int ftp_user_cmd </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>user_cmd</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>格式化指令,对错误指令返回ERROR flag </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">user_cmd</td><td>用户输入的指令 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>cmd_flag，用于指示调用何种功能函数完成指令 </dd></dl>

</div>
</div>
<a id="ac95cce0b3a2123cc408859183557ab80" name="ac95cce0b3a2123cc408859183557ab80"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac95cce0b3a2123cc408859183557ab80">&#9670;&nbsp;</a></span>get_port()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int get_port </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>pasv模式下，向server发送PASV指令，接收server发回的端口号（第一次握手 </p>
<dl class="section return"><dt>Returns</dt><dd>若执行成功，返回server打开的端口号；否则返回0。 </dd></dl>

</div>
</div>
<a id="a0d2d0ee5a8e9a4e4a5f215b52d7e73c2" name="a0d2d0ee5a8e9a4e4a5f215b52d7e73c2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0d2d0ee5a8e9a4e4a5f215b52d7e73c2">&#9670;&nbsp;</a></span>rand_local_port()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int rand_local_port </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>PORT模式下，随机生成一个端口号。 </p>
<dl class="section return"><dt>Returns</dt><dd>生成的端口号 </dd></dl>

</div>
</div>
<a id="a2da1039d0b9c00763143e93f44ca7416" name="a2da1039d0b9c00763143e93f44ca7416"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2da1039d0b9c00763143e93f44ca7416">&#9670;&nbsp;</a></span>xconnect()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int xconnect </td>
          <td>(</td>
          <td class="paramtype">struct sockaddr_in *&#160;</td>
          <td class="paramname"><em>s_addr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>连接到服务器。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">s_addr</td><td>socket连接的地址 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功则返回所用套接字的描述符，否则返回-1。 </dd></dl>

</div>
</div>
<a id="a007aca7a47d99c72aea9dac4faa64ce9" name="a007aca7a47d99c72aea9dac4faa64ce9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a007aca7a47d99c72aea9dac4faa64ce9">&#9670;&nbsp;</a></span>xconnect_ftpdata()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void xconnect_ftpdata </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structMsg.html">Msg</a> *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>建立数据连接，被动模式下，从server获得端口号，通过server打开的这个端口与server建立数据连接;主动模式下，client指定本地端口号后，向server发PORT指令，然后建立一个新的数据连接。 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">msg</td><td>此函数负责填充msg结构体中的ftp_data_sock </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
